{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Version:  2.1.0\n",
      "Eager mode:  True\n",
      "Hub version:  0.7.0\n",
      "GPU is NOT AVAILABLE\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import tensorflow as tf\n",
    "import tensorflow_hub as hub\n",
    "import tensorflow_datasets as tfds\n",
    "\n",
    "print(\"Version: \", tf.__version__)\n",
    "print(\"Eager mode: \", tf.executing_eagerly())\n",
    "print(\"Hub version: \", hub.__version__)\n",
    "print(\"GPU is\", \"available\" if tf.config.experimental.list_physical_devices(\"GPU\") else \"NOT AVAILABLE\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将训练集按照 6:4 的比例进行切割，从而最终我们将得到 15,000\n",
    "# 个训练样本, 10,000 个验证样本以及 25,000 个测试样本\n",
    "(train_data, validation_data, test_data) = tfds.load(\n",
    "    name=\"imdb_reviews\",\n",
    "    split=('train[:60%]', 'train[60%:]', 'test'),\n",
    "    as_supervised=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(10,), dtype=string, numpy=\n",
       "array([b'This is a big step down after the surprisingly enjoyable original. This sequel isn\\'t nearly as fun as part one, and it instead spends too much time on plot development. Tim Thomerson is still the best thing about this series, but his wisecracking is toned down in this entry. The performances are all adequate, but this time the script lets us down. The action is merely routine and the plot is only mildly interesting, so I need lots of silly laughs in order to stay entertained during a \"Trancers\" movie. Unfortunately, the laughs are few and far between, and so, this film is watchable at best.',\n",
       "       b\"Perhaps because I was so young, innocent and BRAINWASHED when I saw it, this movie was the cause of many sleepless nights for me. I haven't seen it since I was in seventh grade at a Presbyterian school, so I am not sure what effect it would have on me now. However, I will say that it left an impression on me... and most of my friends. It did serve its purpose, at least until we were old enough and knowledgeable enough to analyze and create our own opinions. I was particularly terrified of what the newly-converted post-rapture Christians had to endure when not receiving the mark of the beast. I don't want to spoil the movie for those who haven't seen it so I will not mention details of the scenes, but I can still picture them in my head... and it's been 19 years.\",\n",
       "       b'Hood of the Living Dead had a lot to live up to even before the opening credits began. First, any play on \"...of the living dead\" invokes His Holiness Mr. Romero and instantly sets up a high standard to which many movies cannot afford to aspire. And second, my movie-watching companion professed doubt that any urban horror film would surpass the seminal Leprechaun In the Hood. Skeptical, we settled in to watch. <br /><br />We were rewarded with a surprisingly sincere and good-hearted zombie film. Oh, certainly the budget is low, and of course the directors\\' amateurs friends populate the cast, but Hood of the Living Dead loves zombie cinema. Cheap? Yeah. But when it\\'s this cheap, you can clearly see where LOVE holds it together. <br /><br />Ricky works in a lab during the day and as a surrogate parent to his younger brother at night. He dreams of moving out of Oakland. Before this planned escape, however, his brother is shot to death in a drive-by. Ricky\\'s keen scientific mind presents an option superior to CPR or 911: injections of his lab\\'s experimental regenerative formula. Sadly, little bro wakes up in an ambulance as a bloodthirsty Oakland zombie! Chaos and mayhem! I think it\\'s more economical to eat your enemies than take vengeance in a drive-by, but then again, I\\'m a poor judge of the complexities of urban life. (How poor a judge? In response to a gory scene involving four men, I opined \"Ah-ha! White t-shirts on everyone so the blood shows up. Economical! I used the same technique in my own low-budget horror film.\" Jordan replied, \"No, that\\'s gang dress. White t-shirts were banned from New Orleans bars for a time as a result.\" Oh.)<br /><br />A lot of the movie is set in someone\\'s living room, so there\\'s a great deal of hanging out and waiting for the zombies. But the characters are sympathetic and the movie is sincere-- it surpasses its budget in spirit. <br /><br />Zombie explanation: When man plays God, zombies arise! Or, perhaps: Follow FDA-approved testing rules before human experimentation! <br /><br />Contribution to the zombie canon: This is the first zombie movie I\\'ve seen with a drive-by shooting. As far as the actual zombies go, infection is spread with a bite as usual, but quite unusually head shots don\\'t work-- it\\'s heart shots that kill. Zombies have pulses, the absence of which proves true death. And these zombies make pretty cool jaguar-growl noises. <br /><br />Gratuitous zombie movie in-joke: A mercenary named Romero. Groan. <br /><br />Favorite zombie: Jaguar-noise little brother zombie, of course!',\n",
       "       b\"For me this is a story that starts with some funny jokes regarding Franks fanatasies when he is travelling with a staircase and when he is sitting in business meetings... The problem is that when you have been watching this movie for an hour you will see the same fantasies/funny situations again and again and again. It is to predictable. It is more done as a TV story where you can go away and come back without missing anything.<br /><br />I like Felix Herngren as Frank but that is not enough even when it is a comedy it has to have more variations and some kind of message to it's audience....<br /><br />\",\n",
       "       b'This is not a bad movie. It follows the new conventions of modern horror, that is the movie within a movie, the well known actress running for her life in the first scene. This movie takes the old convention of a psycho killer on he loose, and manage to do something new, and interesting with it. It is also always nice to see Molly Ringwald back for the attack.<br /><br />So this might be an example of what the genre has become. Cut hits all the marks, and is actually scary in some parts. I liked it I gave it an eight.',\n",
       "       b\"I just finished a marathon of this series, and it became agonising to watch as it progressed. From the fictionalising of the historical elements, to O'Herlihy's awful accent in later episodes, the show just slumps the further it goes. If you are looking for some low quality production generalised WW2 fluff, then I could recommend season 1, but avoid anything after that, it degenerates into being one step from a soap opera, with increasingly worse story lines and sensibility.<br /><br />The old B&W film is by far the best of any form of entertainment with the Colditz name attached to it, and even that is not what one could hope for.\",\n",
       "       b'I am very sorry that this charming and whimsical film (which I first saw soon after it was first released in the early fifties) has had such a poor reception more recently. In my opinion it has been greatly underrated - but perhaps it appeals more to the European sense of humour than to (for example) the American: maybe we in Europe can understand and appreciate its subtleties and situations more, since we are closer to some of them in real life! Particular mention should be made of the limited but good music - especially the catchy and memorable song \"It\\'s a fine, fine night\", which was issued separately on an HMV 78rpm record (10 inch plum label, I think!) in the fifties. I would urge anyone interested to give it a try if you get the chance: you may have a pleasant surprise.',\n",
       "       b\"Well i am going to go against the grain on this film so it seems. Being a self confessed horror fan I sat down to this not quite knowing what to expect. After 2 or 3 mins i actually found myself scared (quite rare). The film obviously has a small budget and is set around charing cross station but the films lack of money does not distract from the story. Yes the story is a bit far fetched and doesn't explain itself very well but THE CREEP is a class act and proceeds to slash and dismember anything that comes its way. MESSAGE FOR LADIES !!! THERE ARE CERTAIN PARTS OF THE FILM YOU SHOULD CLOSE YOUR EYES AT OR AT LEAST CROSS YOUR LEGS !! you will understand when you see it.<br /><br />All in all a good film and it makes a change to see a good slasher movie that actually scares\",\n",
       "       b'Even 15 years after the end of the Vietnam war \"Jacknife\" came not too late or was even superfluous. It\\'s one of the few that try to deal with the second sad side of the war: The time after. Different from movies like \"Taxi driver\" or \"Rambo\" which use to present their main characters as broken heroes in a bad after war environment this movie allows the audience to face a different view on the Vietnam vets. Their development is shown very precisely before and especially after the war. The problems are obvious but in all this tragic there is always the feeling of some hope on the basis of love and friendship. \"Jacknife\" might be the quietest Vietnam movie ever but after almost 15 years this is really plausible and therefor justified. Moreover, it can make us believe that the war has not finished, yet; at least for some of us.<br /><br />The three main characters are amazing. De Niro has done one of his best jobs but Ed Harris is the star of this movie. Possibly,this was his best performance ever.',\n",
       "       b'Before I explain the \"Alias\" comment let me say that \"The Desert Trail\" is bad even by the standards of westerns staring The Three Stooges. In fact it features Carmen Laroux as semi- bad girl Juanita, when you hear her Mexican accent you will immediately recognize her as Senorita Rita from the classic Stooge short \"Saved by the Belle\". <br /><br />In \"The Desert Trail\" John Wayne gets to play the Moe Howard character and Eddy Chandler gets to play Curly Howard. Like their Stooge counterparts a running gag throughout the 53- minute movie is Moe hitting Curly. Wayne\\'s character, a skirt chasing bully, is not very endearing, but is supposed to be the good guy. <br /><br />Playing a traveling rodeo cowboy Wayne holds up the rodeo box office at gunpoint and takes the prize money he would have won if the attendance proceeds had been good-the other riders have to settle for 25 cents on the dollar (actually even less after Wayne robs the box office). No explanation is given for Wayne\\'s ripping off the riders and still being considered the hero who gets the girl. <br /><br />Things get complicated at this point because the villain (Al Ferguson) and his sidekick Larry Fine (played by Paul Fix-who would go on to play Sheriff Micah on television\\'s \"The Rifleman\") see Wayne rob the box office and then steal the remainder of the money and kill the rodeo manager. Moe and Curly get blamed. <br /><br />So Moe and Curly move to another town to get away from the law and they change their names to Smith and Jones. Who do they meet first but their old friend Larry, whose sister becomes the 2nd half love interest (Senorita Rita is left behind it the old town and makes no further appearances in the movie). <br /><br />Larry\\'s sister is nicely played by a radiantly beautiful Mary Kornman (now grown up but in her younger days she was one of the original cast members of Hal Roach\\'s \"Our Gang\" shorts). Kornman is the main reason to watch the mega-lame western and her scenes with Moe and Curly are much better than any others in the production, as if they used an entirely different crew to film them. <br /><br />Even for 1935 the action sequences in this thing are extremely weak and the technical film- making is staggeringly bad. The two main chase scenes end with stock footage wide shots of a rider falling from a horse. Both times the editor cuts to a shot of one of the characters rolling on the ground, but there is no horse in the frame, the film stock is completely different, and the character has on different clothes than the stunt rider. There is liberal use of stock footage in other places, none of it even remotely convincing. <br /><br />One thing to watch for is a scene midway into the movie where Moe and Curly get on their horses and ride away (to screen right) from a cabin as the posse is galloping toward the cabin from the left. The cameraman follows the two stooges with a slow pan right and then does a whip pan to the left to reveal the approaching posse. Outside of home movies I have never seen anything like this, not because it is looks stupid (which it does) but because a competent director would never stage a scene in this manner. They would film the two riders leaving and then reposition the camera and film the posse approaching as a separate action. Or if they were feeling creative they would stage the sequence so the camera shows the riders in the foreground and the posse approaching in the background. <br /><br />Then again, what do I know? I\\'m only a child.'],\n",
       "      dtype=object)>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_examples_batch,train_labels_batch = next(iter(train_data.batch(10)))\n",
    "train_examples_batch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(10,), dtype=int64, numpy=array([0, 0, 1, 0, 1, 0, 1, 1, 1, 0], dtype=int64)>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_labels_batch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(3, 20), dtype=float32, numpy=\n",
       "array([[ 2.209591  , -2.7093675 ,  3.6802928 , -1.0291991 , -4.1671185 ,\n",
       "        -2.4566064 , -2.2519937 , -0.36589956,  1.9485804 , -3.1104462 ,\n",
       "        -2.4610963 ,  1.3139242 , -0.9161584 , -0.16625322, -3.723651  ,\n",
       "         1.8498232 ,  3.499562  , -1.2373022 , -2.8403084 , -1.213074  ],\n",
       "       [ 1.9055302 , -4.11395   ,  3.6038654 ,  0.28555924, -4.658998  ,\n",
       "        -5.5433393 , -3.2735848 ,  1.9235417 ,  3.8461034 ,  1.5882455 ,\n",
       "        -2.64167   ,  0.76057523, -0.14820506,  0.9115291 , -6.45758   ,\n",
       "         2.3990374 ,  5.0985413 , -3.2776263 , -3.2652326 , -1.2345369 ],\n",
       "       [ 3.6510668 , -4.7066135 ,  4.71003   , -1.7002777 , -3.7708545 ,\n",
       "        -3.709126  , -4.222776  ,  1.946586  ,  6.1182513 , -2.7392752 ,\n",
       "        -5.4384456 ,  2.7078724 , -2.1263676 , -0.7084146 , -5.893995  ,\n",
       "         3.1602864 ,  3.8389287 , -3.318196  , -5.1542974 , -2.4051712 ]],\n",
       "      dtype=float32)>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "embedding = \"https://hub.tensorflow.google.cn/google/tf2-preview/gnews-swivel-20dim/1\"\n",
    "hub_layer = hub.KerasLayer(embedding,input_shape=[],\n",
    "                          dtype=tf.string,trainable=True)\n",
    "hub_layer(train_examples_batch[:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(), dtype=string, numpy=b'This is a big step down after the surprisingly enjoyable original. This sequel isn\\'t nearly as fun as part one, and it instead spends too much time on plot development. Tim Thomerson is still the best thing about this series, but his wisecracking is toned down in this entry. The performances are all adequate, but this time the script lets us down. The action is merely routine and the plot is only mildly interesting, so I need lots of silly laughs in order to stay entertained during a \"Trancers\" movie. Unfortunately, the laughs are few and far between, and so, this film is watchable at best.'>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_examples_batch[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "keras_layer (KerasLayer)     (None, 20)                400020    \n",
      "_________________________________________________________________\n",
      "dense (Dense)                (None, 16)                336       \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 1)                 17        \n",
      "=================================================================\n",
      "Total params: 400,373\n",
      "Trainable params: 400,373\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model = tf.keras.Sequential()\n",
    "model.add(hub_layer)\n",
    "model.add(tf.keras.layers.Dense(16,activation='relu'))\n",
    "model.add(tf.keras.layers.Dense(1,activation='sigmoid'))\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.compile(optimizer='adam',\n",
    "             loss='binary_crossentropy',\n",
    "             metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/10\n",
      "30/30 [==============================].9851 - accuracy: 0.43 - 2s 769ms/step - loss: 0.9482 - accuracy: 0.452 - 2s 544ms/step - loss: 0.9236 - accuracy: 0.455 - 2s 429ms/step - loss: 0.9043 - accuracy: 0.466 - 2s 358ms/step - loss: 0.8790 - accuracy: 0.481 - 2s 313ms/step - loss: 0.8589 - accuracy: 0.488 - 2s 279ms/step - loss: 0.8437 - accuracy: 0.497 - 2s 257ms/step - loss: 0.8408 - accuracy: 0.497 - 2s 238ms/step - loss: 0.8337 - accuracy: 0.503 - 2s 222ms/step - loss: 0.8320 - accuracy: 0.502 - 2s 210ms/step - loss: 0.8285 - accuracy: 0.503 - 2s 200ms/step - loss: 0.8224 - accuracy: 0.510 - 2s 192ms/step - loss: 0.8172 - accuracy: 0.514 - 3s 184ms/step - loss: 0.8148 - accuracy: 0.517 - 3s 178ms/step - loss: 0.8104 - accuracy: 0.521 - 3s 172ms/step - loss: 0.8051 - accuracy: 0.524 - 3s 167ms/step - loss: 0.8016 - accuracy: 0.527 - 3s 162ms/step - loss: 0.7989 - accuracy: 0.528 - 3s 158ms/step - loss: 0.7974 - accuracy: 0.530 - 3s 154ms/step - loss: 0.7942 - accuracy: 0.531 - 3s 151ms/step - loss: 0.7912 - accuracy: 0.534 - 3s 148ms/step - loss: 0.7900 - accuracy: 0.536 - 3s 145ms/step - loss: 0.7874 - accuracy: 0.537 - 3s 143ms/step - loss: 0.7834 - accuracy: 0.540 - 4s 141ms/step - loss: 0.7815 - accuracy: 0.541 - 4s 139ms/step - loss: 0.7800 - accuracy: 0.541 - 4s 137ms/step - loss: 0.7770 - accuracy: 0.543 - 4s 135ms/step - loss: 0.7731 - accuracy: 0.546 - 4s 134ms/step - loss: 0.7719 - accuracy: 0.546 - 4s 131ms/step - loss: 0.7687 - accuracy: 0.546 - 6s 189ms/step - loss: 0.7687 - accuracy: 0.5469 - val_loss: 0.7085 - val_accuracy: 0.5714\n",
      "Epoch 2/10\n",
      "30/30 [==============================] - ETA: 14s - loss: 0.6609 - accuracy: 0.619 - ETA: 8s - loss: 0.6714 - accuracy: 0.616 - ETA: 6s - loss: 0.6718 - accuracy: 0.61 - ETA: 5s - loss: 0.6749 - accuracy: 0.61 - ETA: 4s - loss: 0.6796 - accuracy: 0.60 - ETA: 4s - loss: 0.6769 - accuracy: 0.60 - ETA: 3s - loss: 0.6783 - accuracy: 0.60 - ETA: 3s - loss: 0.6757 - accuracy: 0.60 - ETA: 3s - loss: 0.6755 - accuracy: 0.60 - ETA: 2s - loss: 0.6777 - accuracy: 0.60 - ETA: 2s - loss: 0.6778 - accuracy: 0.60 - ETA: 2s - loss: 0.6749 - accuracy: 0.60 - ETA: 2s - loss: 0.6738 - accuracy: 0.60 - ETA: 2s - loss: 0.6733 - accuracy: 0.60 - ETA: 1s - loss: 0.6716 - accuracy: 0.60 - ETA: 1s - loss: 0.6711 - accuracy: 0.60 - ETA: 1s - loss: 0.6687 - accuracy: 0.61 - ETA: 1s - loss: 0.6678 - accuracy: 0.61 - ETA: 1s - loss: 0.6688 - accuracy: 0.61 - ETA: 1s - loss: 0.6674 - accuracy: 0.61 - ETA: 1s - loss: 0.6669 - accuracy: 0.61 - ETA: 0s - loss: 0.6649 - accuracy: 0.61 - ETA: 0s - loss: 0.6644 - accuracy: 0.61 - ETA: 0s - loss: 0.6623 - accuracy: 0.61 - ETA: 0s - loss: 0.6623 - accuracy: 0.61 - ETA: 0s - loss: 0.6600 - accuracy: 0.61 - ETA: 0s - loss: 0.6588 - accuracy: 0.61 - ETA: 0s - loss: 0.6586 - accuracy: 0.62 - ETA: 0s - loss: 0.6572 - accuracy: 0.62 - 5s 158ms/step - loss: 0.6541 - accuracy: 0.6230 - val_loss: 0.6232 - val_accuracy: 0.6574\n",
      "Epoch 3/10\n",
      "30/30 [==============================] - ETA: 12s - loss: 0.6115 - accuracy: 0.656 - ETA: 7s - loss: 0.5992 - accuracy: 0.672 - ETA: 5s - loss: 0.6035 - accuracy: 0.67 - ETA: 4s - loss: 0.6043 - accuracy: 0.68 - ETA: 3s - loss: 0.6078 - accuracy: 0.67 - ETA: 3s - loss: 0.6055 - accuracy: 0.67 - ETA: 3s - loss: 0.6061 - accuracy: 0.67 - ETA: 2s - loss: 0.6089 - accuracy: 0.67 - ETA: 2s - loss: 0.6058 - accuracy: 0.68 - ETA: 2s - loss: 0.6049 - accuracy: 0.68 - ETA: 2s - loss: 0.6073 - accuracy: 0.68 - ETA: 2s - loss: 0.6072 - accuracy: 0.67 - ETA: 1s - loss: 0.6060 - accuracy: 0.67 - ETA: 1s - loss: 0.6032 - accuracy: 0.68 - ETA: 1s - loss: 0.6021 - accuracy: 0.68 - ETA: 1s - loss: 0.6000 - accuracy: 0.68 - ETA: 1s - loss: 0.5994 - accuracy: 0.68 - ETA: 1s - loss: 0.5967 - accuracy: 0.68 - ETA: 1s - loss: 0.5960 - accuracy: 0.68 - ETA: 1s - loss: 0.5974 - accuracy: 0.68 - ETA: 0s - loss: 0.5976 - accuracy: 0.68 - ETA: 0s - loss: 0.5979 - accuracy: 0.68 - ETA: 0s - loss: 0.5972 - accuracy: 0.68 - ETA: 0s - loss: 0.5961 - accuracy: 0.68 - ETA: 0s - loss: 0.5946 - accuracy: 0.68 - ETA: 0s - loss: 0.5939 - accuracy: 0.68 - ETA: 0s - loss: 0.5930 - accuracy: 0.68 - ETA: 0s - loss: 0.5920 - accuracy: 0.68 - ETA: 0s - loss: 0.5926 - accuracy: 0.68 - 4s 146ms/step - loss: 0.5934 - accuracy: 0.6870 - val_loss: 0.5732 - val_accuracy: 0.7055\n",
      "Epoch 4/10\n",
      "30/30 [==============================] - ETA: 13s - loss: 0.5350 - accuracy: 0.728 - ETA: 7s - loss: 0.5587 - accuracy: 0.702 - ETA: 5s - loss: 0.5628 - accuracy: 0.69 - ETA: 4s - loss: 0.5551 - accuracy: 0.70 - ETA: 4s - loss: 0.5595 - accuracy: 0.70 - ETA: 3s - loss: 0.5625 - accuracy: 0.70 - ETA: 3s - loss: 0.5610 - accuracy: 0.70 - ETA: 2s - loss: 0.5599 - accuracy: 0.71 - ETA: 2s - loss: 0.5549 - accuracy: 0.71 - ETA: 2s - loss: 0.5530 - accuracy: 0.71 - ETA: 2s - loss: 0.5535 - accuracy: 0.71 - ETA: 2s - loss: 0.5550 - accuracy: 0.71 - ETA: 1s - loss: 0.5570 - accuracy: 0.71 - ETA: 1s - loss: 0.5585 - accuracy: 0.71 - ETA: 1s - loss: 0.5573 - accuracy: 0.71 - ETA: 1s - loss: 0.5581 - accuracy: 0.71 - ETA: 1s - loss: 0.5575 - accuracy: 0.71 - ETA: 1s - loss: 0.5565 - accuracy: 0.71 - ETA: 1s - loss: 0.5570 - accuracy: 0.71 - ETA: 1s - loss: 0.5549 - accuracy: 0.71 - ETA: 0s - loss: 0.5542 - accuracy: 0.71 - ETA: 0s - loss: 0.5539 - accuracy: 0.71 - ETA: 0s - loss: 0.5527 - accuracy: 0.71 - ETA: 0s - loss: 0.5513 - accuracy: 0.71 - ETA: 0s - loss: 0.5512 - accuracy: 0.72 - ETA: 0s - loss: 0.5504 - accuracy: 0.72 - ETA: 0s - loss: 0.5493 - accuracy: 0.72 - ETA: 0s - loss: 0.5486 - accuracy: 0.72 - ETA: 0s - loss: 0.5482 - accuracy: 0.72 - 4s 146ms/step - loss: 0.5488 - accuracy: 0.7229 - val_loss: 0.5380 - val_accuracy: 0.7342\n",
      "Epoch 5/10\n",
      "30/30 [==============================] - ETA: 14s - loss: 0.5364 - accuracy: 0.726 - ETA: 8s - loss: 0.5486 - accuracy: 0.714 - ETA: 6s - loss: 0.5288 - accuracy: 0.73 - ETA: 5s - loss: 0.5266 - accuracy: 0.73 - ETA: 4s - loss: 0.5232 - accuracy: 0.73 - ETA: 3s - loss: 0.5210 - accuracy: 0.74 - ETA: 3s - loss: 0.5210 - accuracy: 0.74 - ETA: 3s - loss: 0.5172 - accuracy: 0.74 - ETA: 2s - loss: 0.5185 - accuracy: 0.74 - ETA: 2s - loss: 0.5176 - accuracy: 0.74 - ETA: 2s - loss: 0.5192 - accuracy: 0.74 - ETA: 2s - loss: 0.5162 - accuracy: 0.74 - ETA: 2s - loss: 0.5181 - accuracy: 0.74 - ETA: 1s - loss: 0.5167 - accuracy: 0.74 - ETA: 1s - loss: 0.5152 - accuracy: 0.74 - ETA: 1s - loss: 0.5144 - accuracy: 0.74 - ETA: 1s - loss: 0.5157 - accuracy: 0.74 - ETA: 1s - loss: 0.5142 - accuracy: 0.74 - ETA: 1s - loss: 0.5144 - accuracy: 0.74 - ETA: 1s - loss: 0.5137 - accuracy: 0.74 - ETA: 1s - loss: 0.5113 - accuracy: 0.75 - ETA: 0s - loss: 0.5118 - accuracy: 0.75 - ETA: 0s - loss: 0.5112 - accuracy: 0.75 - ETA: 0s - loss: 0.5107 - accuracy: 0.75 - ETA: 0s - loss: 0.5097 - accuracy: 0.75 - ETA: 0s - loss: 0.5093 - accuracy: 0.75 - ETA: 0s - loss: 0.5098 - accuracy: 0.75 - ETA: 0s - loss: 0.5101 - accuracy: 0.75 - ETA: 0s - loss: 0.5111 - accuracy: 0.75 - 5s 153ms/step - loss: 0.5093 - accuracy: 0.7531 - val_loss: 0.5084 - val_accuracy: 0.7525\n",
      "Epoch 6/10\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30/30 [==============================] - ETA: 12s - loss: 0.5077 - accuracy: 0.757 - ETA: 7s - loss: 0.5012 - accuracy: 0.749 - ETA: 5s - loss: 0.4929 - accuracy: 0.76 - ETA: 4s - loss: 0.4887 - accuracy: 0.76 - ETA: 3s - loss: 0.4889 - accuracy: 0.76 - ETA: 3s - loss: 0.4858 - accuracy: 0.76 - ETA: 3s - loss: 0.4857 - accuracy: 0.76 - ETA: 2s - loss: 0.4867 - accuracy: 0.76 - ETA: 2s - loss: 0.4828 - accuracy: 0.77 - ETA: 2s - loss: 0.4838 - accuracy: 0.77 - ETA: 2s - loss: 0.4843 - accuracy: 0.76 - ETA: 2s - loss: 0.4855 - accuracy: 0.76 - ETA: 1s - loss: 0.4864 - accuracy: 0.76 - ETA: 1s - loss: 0.4855 - accuracy: 0.76 - ETA: 1s - loss: 0.4846 - accuracy: 0.76 - ETA: 1s - loss: 0.4825 - accuracy: 0.77 - ETA: 1s - loss: 0.4805 - accuracy: 0.77 - ETA: 1s - loss: 0.4812 - accuracy: 0.77 - ETA: 1s - loss: 0.4821 - accuracy: 0.77 - ETA: 1s - loss: 0.4822 - accuracy: 0.77 - ETA: 0s - loss: 0.4819 - accuracy: 0.77 - ETA: 0s - loss: 0.4811 - accuracy: 0.77 - ETA: 0s - loss: 0.4819 - accuracy: 0.77 - ETA: 0s - loss: 0.4817 - accuracy: 0.77 - ETA: 0s - loss: 0.4812 - accuracy: 0.77 - ETA: 0s - loss: 0.4801 - accuracy: 0.77 - ETA: 0s - loss: 0.4796 - accuracy: 0.77 - ETA: 0s - loss: 0.4789 - accuracy: 0.77 - ETA: 0s - loss: 0.4780 - accuracy: 0.77 - 4s 147ms/step - loss: 0.4759 - accuracy: 0.7775 - val_loss: 0.4823 - val_accuracy: 0.7705\n",
      "Epoch 7/10\n",
      "30/30 [==============================] - ETA: 13s - loss: 0.4508 - accuracy: 0.783 - ETA: 7s - loss: 0.4503 - accuracy: 0.790 - ETA: 5s - loss: 0.4502 - accuracy: 0.79 - ETA: 4s - loss: 0.4543 - accuracy: 0.78 - ETA: 3s - loss: 0.4502 - accuracy: 0.79 - ETA: 3s - loss: 0.4559 - accuracy: 0.78 - ETA: 3s - loss: 0.4555 - accuracy: 0.78 - ETA: 2s - loss: 0.4506 - accuracy: 0.79 - ETA: 2s - loss: 0.4545 - accuracy: 0.79 - ETA: 2s - loss: 0.4545 - accuracy: 0.79 - ETA: 2s - loss: 0.4552 - accuracy: 0.79 - ETA: 2s - loss: 0.4536 - accuracy: 0.79 - ETA: 1s - loss: 0.4545 - accuracy: 0.79 - ETA: 1s - loss: 0.4534 - accuracy: 0.79 - ETA: 1s - loss: 0.4544 - accuracy: 0.79 - ETA: 1s - loss: 0.4521 - accuracy: 0.79 - ETA: 1s - loss: 0.4517 - accuracy: 0.79 - ETA: 1s - loss: 0.4503 - accuracy: 0.79 - ETA: 1s - loss: 0.4502 - accuracy: 0.79 - ETA: 1s - loss: 0.4490 - accuracy: 0.79 - ETA: 0s - loss: 0.4480 - accuracy: 0.79 - ETA: 0s - loss: 0.4485 - accuracy: 0.79 - ETA: 0s - loss: 0.4483 - accuracy: 0.79 - ETA: 0s - loss: 0.4484 - accuracy: 0.79 - ETA: 0s - loss: 0.4484 - accuracy: 0.79 - ETA: 0s - loss: 0.4482 - accuracy: 0.79 - ETA: 0s - loss: 0.4474 - accuracy: 0.79 - ETA: 0s - loss: 0.4461 - accuracy: 0.80 - ETA: 0s - loss: 0.4468 - accuracy: 0.79 - 5s 151ms/step - loss: 0.4447 - accuracy: 0.8000 - val_loss: 0.4579 - val_accuracy: 0.7873\n",
      "Epoch 8/10\n",
      "30/30 [==============================] - ETA: 12s - loss: 0.4196 - accuracy: 0.812 - ETA: 7s - loss: 0.4302 - accuracy: 0.813 - ETA: 5s - loss: 0.4400 - accuracy: 0.80 - ETA: 4s - loss: 0.4384 - accuracy: 0.79 - ETA: 4s - loss: 0.4387 - accuracy: 0.79 - ETA: 3s - loss: 0.4339 - accuracy: 0.80 - ETA: 3s - loss: 0.4343 - accuracy: 0.80 - ETA: 3s - loss: 0.4296 - accuracy: 0.80 - ETA: 2s - loss: 0.4287 - accuracy: 0.80 - ETA: 2s - loss: 0.4279 - accuracy: 0.80 - ETA: 2s - loss: 0.4244 - accuracy: 0.81 - ETA: 2s - loss: 0.4235 - accuracy: 0.81 - ETA: 2s - loss: 0.4220 - accuracy: 0.81 - ETA: 1s - loss: 0.4225 - accuracy: 0.81 - ETA: 1s - loss: 0.4224 - accuracy: 0.81 - ETA: 1s - loss: 0.4227 - accuracy: 0.81 - ETA: 1s - loss: 0.4232 - accuracy: 0.81 - ETA: 1s - loss: 0.4224 - accuracy: 0.81 - ETA: 1s - loss: 0.4208 - accuracy: 0.81 - ETA: 1s - loss: 0.4214 - accuracy: 0.81 - ETA: 0s - loss: 0.4203 - accuracy: 0.81 - ETA: 0s - loss: 0.4195 - accuracy: 0.81 - ETA: 0s - loss: 0.4192 - accuracy: 0.81 - ETA: 0s - loss: 0.4197 - accuracy: 0.81 - ETA: 0s - loss: 0.4175 - accuracy: 0.81 - ETA: 0s - loss: 0.4178 - accuracy: 0.81 - ETA: 0s - loss: 0.4172 - accuracy: 0.81 - ETA: 0s - loss: 0.4175 - accuracy: 0.81 - ETA: 0s - loss: 0.4171 - accuracy: 0.81 - 5s 151ms/step - loss: 0.4157 - accuracy: 0.8177 - val_loss: 0.4345 - val_accuracy: 0.8008\n",
      "Epoch 9/10\n",
      "30/30 [==============================] - ETA: 12s - loss: 0.3931 - accuracy: 0.830 - ETA: 7s - loss: 0.3916 - accuracy: 0.835 - ETA: 5s - loss: 0.3920 - accuracy: 0.84 - ETA: 4s - loss: 0.3946 - accuracy: 0.83 - ETA: 3s - loss: 0.3942 - accuracy: 0.83 - ETA: 3s - loss: 0.3961 - accuracy: 0.83 - ETA: 3s - loss: 0.3935 - accuracy: 0.83 - ETA: 2s - loss: 0.3953 - accuracy: 0.83 - ETA: 2s - loss: 0.3997 - accuracy: 0.82 - ETA: 2s - loss: 0.3989 - accuracy: 0.83 - ETA: 2s - loss: 0.3979 - accuracy: 0.83 - ETA: 2s - loss: 0.3988 - accuracy: 0.83 - ETA: 1s - loss: 0.3992 - accuracy: 0.83 - ETA: 1s - loss: 0.3998 - accuracy: 0.83 - ETA: 1s - loss: 0.3978 - accuracy: 0.83 - ETA: 1s - loss: 0.3980 - accuracy: 0.82 - ETA: 1s - loss: 0.3969 - accuracy: 0.82 - ETA: 1s - loss: 0.3972 - accuracy: 0.82 - ETA: 1s - loss: 0.3968 - accuracy: 0.82 - ETA: 1s - loss: 0.3960 - accuracy: 0.83 - ETA: 0s - loss: 0.3937 - accuracy: 0.83 - ETA: 0s - loss: 0.3927 - accuracy: 0.83 - ETA: 0s - loss: 0.3921 - accuracy: 0.83 - ETA: 0s - loss: 0.3920 - accuracy: 0.83 - ETA: 0s - loss: 0.3908 - accuracy: 0.83 - ETA: 0s - loss: 0.3891 - accuracy: 0.83 - ETA: 0s - loss: 0.3891 - accuracy: 0.83 - ETA: 0s - loss: 0.3894 - accuracy: 0.83 - ETA: 0s - loss: 0.3887 - accuracy: 0.83 - 5s 152ms/step - loss: 0.3864 - accuracy: 0.8353 - val_loss: 0.4149 - val_accuracy: 0.8125\n",
      "Epoch 10/10\n",
      "30/30 [==============================] - ETA: 11s - loss: 0.3769 - accuracy: 0.837 - ETA: 6s - loss: 0.3819 - accuracy: 0.828 - ETA: 5s - loss: 0.3811 - accuracy: 0.83 - ETA: 4s - loss: 0.3919 - accuracy: 0.82 - ETA: 3s - loss: 0.3864 - accuracy: 0.83 - ETA: 3s - loss: 0.3844 - accuracy: 0.83 - ETA: 2s - loss: 0.3823 - accuracy: 0.83 - ETA: 2s - loss: 0.3781 - accuracy: 0.83 - ETA: 2s - loss: 0.3778 - accuracy: 0.83 - ETA: 2s - loss: 0.3778 - accuracy: 0.83 - ETA: 2s - loss: 0.3802 - accuracy: 0.83 - ETA: 2s - loss: 0.3784 - accuracy: 0.83 - ETA: 1s - loss: 0.3789 - accuracy: 0.83 - ETA: 1s - loss: 0.3790 - accuracy: 0.83 - ETA: 1s - loss: 0.3775 - accuracy: 0.83 - ETA: 1s - loss: 0.3777 - accuracy: 0.83 - ETA: 1s - loss: 0.3773 - accuracy: 0.83 - ETA: 1s - loss: 0.3778 - accuracy: 0.83 - ETA: 1s - loss: 0.3768 - accuracy: 0.83 - ETA: 1s - loss: 0.3743 - accuracy: 0.84 - ETA: 0s - loss: 0.3710 - accuracy: 0.84 - ETA: 0s - loss: 0.3689 - accuracy: 0.84 - ETA: 0s - loss: 0.3667 - accuracy: 0.84 - ETA: 0s - loss: 0.3660 - accuracy: 0.84 - ETA: 0s - loss: 0.3652 - accuracy: 0.84 - ETA: 0s - loss: 0.3650 - accuracy: 0.84 - ETA: 0s - loss: 0.3642 - accuracy: 0.84 - ETA: 0s - loss: 0.3629 - accuracy: 0.84 - ETA: 0s - loss: 0.3627 - accuracy: 0.84 - 5s 151ms/step - loss: 0.3626 - accuracy: 0.8489 - val_loss: 0.3992 - val_accuracy: 0.8207\n"
     ]
    }
   ],
   "source": [
    "history = model.fit(train_data.shuffle(10000).batch(512),\n",
    "                   epochs=10,\n",
    "                   validation_data = validation_data.batch(512),\n",
    "                   verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loss: 0.407\n",
      "accuracy: 0.818\n"
     ]
    }
   ],
   "source": [
    "results = model.evaluate(test_data.batch(512),verbose=2)\n",
    "for name,value in zip(model.metrics_names,results):\n",
    "    print(\"%s: %.3f\" % (name, value))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
